$(function () {
    $("#search").css("display","block");
    $("#to_append").css("display","block");
    $("#cancel").css("display","none");
    $("#save").css("display","none");

    $("#seq_input").css("display","none");
})

$("#btn_to_append").click(function () {
    $("#search").css("display","none");
    $("#to_append").css("display","none");
    $("#cancel").css("display","block");
    $("#save").css("display","block");

    $("#className").val("");
    $("#firstId").val(0);
})

$("#btn_cancel").click(function () {
    $("#search").css("display","block");
    $("#to_append").css("display","block");
    $("#cancel").css("display","none");
    $("#save").css("display","none");

    $("#seq_input").css("display","none");

    $("#className").val("");
    $("#firstId").val(0);

    $("#secondId").val(0);
})

$("#btn_save").click(function () {

    var model_path=$("#form1").attr("model_path");
    var submit_url="";

    if( $("#secondId").val()==0){
        submit_url=model_path+"/append";
    }else{
        submit_url=model_path+"/modify";
    }

    $("#form1").prop("action",submit_url).submit();
})

function modifySecondClass(element) {

    $("#search").css("display","none");
    $("#to_append").css("display","none");
    $("#cancel").css("display","block");
    $("#save").css("display","block");

    $("#seq_input").css("display","block");

    var model_path=$("#form1").attr("model_path");
    var id=$(element).attr("id");
    var submit_url=model_path+"/detail?id="+id;

    $.get(submit_url,function (second) {
        $("#className").val(second.className)
        $("#firstId").val(second.firstId);
        $("#seq").val(second.seq);
        $("#secondId").val(second.id);
    });
}